<!--审批列表-->
<template>
  <div>
    <avue-crud :data="reviewData"
               :option="reviewOption"
               :page="reviewPage"
               :table-loading="reviewTableLoading"
               @on-load="getReviewList"
               @search-change="refreshReviewChange"
               class="review-crud">
      <template slot-scope="scope" slot="menu">
        <div class="menu-title" @click.stop="detailReview(scope.row,scope.index)">
          <i class="iconfont iconview icon-primary"></i>
          <p class="menu-title-text">详情</p>
        </div>
        <div class="menu-title" @click.stop="updateReview(scope.row,scope.index)" v-if="parseInt(scope.row.state)<2">
          <i class="iconfont iconalter icon-warning"></i>
          <p class="menu-title-text">修改</p>
        </div>
        <div class="menu-title" @click.stop="submitReview(scope.row,scope.index)" v-if="parseInt(scope.row.state)<2">
          <i class="iconfont iconview icon-primary"></i>
          <p class="menu-title-text">提交</p>
        </div>
      </template>
    </avue-crud>
    <el-dialog
      title=""
      :visible.sync="dialogVisibleReview"
      width="70%">
      <h2 style="margin-top: -20px;margin-bottom: -10px;">审批详情：</h2>
      <div class="dial">
        <bostech-detail :detail-data="reviewDetailData"></bostech-detail>
      </div>
      <div style="text-align: center;">
          <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisibleReview = false">关 闭</el-button>
            </span>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { reviewList,reviewSubmit } from "@/api/review";
import {REVIEW_DIC} from "@/const/dict";
import getReviewDetail from "@/mixins/review/getReviewDetail";
export default {
  name: "reviewList",
  mixins: [getReviewDetail()],
  props: {
    achievementId:''
  },
  data(){
    return {
      reviewPage: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      reviewData: [],//审批情况列表
      //审批情况表格类型
      reviewOption: {
        page: true,
        menuWidth:230,
        addBtn: false,
        editBtn: false,
        addRowBtn: false,
        indexLabel: "序号",
        index: true,
        indexWidth:70,
        cellBtn: false,
        delBtn: false,
        columnBtn: false,
        refreshBtn: false,
        filterBtn: false,
        searchBtn:false,
        keyId: "id",
        column: [
          {
            label: "标题",
            width: 500,
            prop: "achievementTitle",
            cell: true
          },
          {
            label: "发布范围",
            prop: "openScope",
            type: "select",
            dicData: REVIEW_DIC.publishDIC,
            cell: true,
          }
        ]
      },
      reviewTableLoading: false,
      // 审批列表是否有显示标志
      reviewHaveDataFlag:true,
      // 审批详情弹框标志
      dialogVisibleReview:false,
    }
  },
  methods:{
// 获取审批情况 （审批详情相关方法）
    getReviewList(page,params){
      reviewList(Object.assign({
        current: page.currentPage,
        size: page.pageSize,
        achievementId:this.achievementId
      },params)).then(response => {
        this.reviewData = response.data.data.records;
        this.reviewPage.total = response.data.data.total;
        this.reviewTableLoading = false;
        if(this.reviewData.length>0){
          this.reviewHaveDataFlag = true;
        }else{
          this.reviewHaveDataFlag = false;
        }
        this.$emit('haveDataFlag',this.reviewHaveDataFlag)
      })
    },
    refreshReviewChange(){
      this.getReviewList(this.reviewPage)
    },
    // 提交审批
    submitReview(row,index){
      this.$confirm("确定提交审批么?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        reviewSubmit(row.reviewId).then(response => {
          if (response.data.data) {
            this.$notify({
              title: '成功',
              message: '提交成功',
              type: 'success',
              duration: 2000
            });
            this.getReviewList(this.reviewPage)
          }
        })
      })
    },
    // 审批修改
    updateReview(row,index){
      let src = `/approvalRelease/detail/${this.$route.params.id}`;
      this.$router.push({
        path: src,
        query:{
          reviewId:row.reviewId
        }
      })
    },
    // 审批详情
    detailReview(row,index){
      this.getDetailData_review(row.reviewId);
      this.dialogVisibleReview = true
    }
  }
};
</script>

